package comp302.prototype.component.panel;

import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;

import comp302.prototype.MainWindow;
import comp302.prototype.settings.LineSettings;

import java.awt.Color;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class LinePanel extends JPanel {
	private static final long serialVersionUID = -9169199115505219873L;

	public LinePanel() {
		JLabel lblThickness = new JLabel("Thickness:");
		JComboBox comboBox = new JComboBox();
		JLabel lblColor = new JLabel("Color:");
		JButton btnChange = new JButton("Change");

		comboBox.addItemListener(new ItemListener() {

			public void itemStateChanged(ItemEvent e) {
				LineSettings.setThickness(Integer.parseInt((String) e.getItem()));
				MainWindow.getSlideController().getCurrent().getEditHandler()
						.updateTempAttributes();
			}
		});

		btnChange.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				Color color = JColorChooser.showDialog(null,
						"Choose Line Color", LineSettings.getColor());

				if (color != null) {
					LineSettings.setColor(color);
					MainWindow.getSlideController().getCurrent().getEditHandler()
							.updateTempAttributes();
				}
			}
		});

		comboBox.setModel(new DefaultComboBoxModel(new String[] { "1", "2",
				"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
				"14", "15", "16", "17", "18", "19", "20", "21", "22", "23",
				"24" }));
		comboBox.setSelectedIndex(2);

		add(lblThickness);
		add(comboBox);
		add(lblColor);
		add(btnChange);
	}

}
